package queue;

/*
 * @Description: 数组模拟队列
 * @param null
 * @return
 * @Author: lim
 * @Date: 2025/2/25 9:58
 */
public class ArrayQueue {
    private int[] arr;
    private int maxSize;
    private int front;
    private int rear;
    public ArrayQueue(int maxSize){
        this.maxSize = maxSize;
        front = -1;
        rear = -1;
        arr = new int[maxSize];
    }
    public boolean isEmpty(){
        return front == rear;
    }
    public boolean isFull(){
        return rear == maxSize - 1;
    }
    public void enqueue(int value){
        if(isFull()){
            System.out.println("Queue is full");
        }else {
            arr[++rear] = value;
            System.out.println("enqueue success");
        }

    }
    public int dequeue(){
        if(isEmpty()){
            throw new RuntimeException("Queue is empty");
        }
            return arr[++front];

    }
    public void printQueue(){
        if(isEmpty()){
            System.out.println("Queue is empty");
        }else{
            for(int i = 0; i <= rear; i++){
                System.out.println(arr[i] + " ");
            }
        }
    }
    public int peek(){
        if(isEmpty()){
            throw new RuntimeException("Queue is empty");
        }else{
            return arr[front + 1];
        }
        }
    }



